package com.weeego.web.action.input;

import com.opensymphony.xwork2.ActionSupport;
import com.sql.weeego.bean.base.CenterConfig;
import com.sql.weeego.bean.base.CenterNews;
import com.sql.weeego.bean.base.CenterNewsType;
import com.weeego.web.base.BaseAction;
import com.weeego.web.base.BaseService;
import com.weeego.web.base.Page;
import com.weeego.web.service.CenterNewsService;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

public class CenterNewsAction extends BaseAction {

	protected final Logger logger = Logger.getLogger(getClass());
	protected BaseService service;

	private Map msg = new HashMap();

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public String index() throws Exception {

		List a = new ArrayList();
		a = this.service
				.findByHql(
						1,
						1,
						" from CenterNews t  where  t.typekey ='weeego01' and  t.pic<> '' order by t.id desc");

		msg.put("index0", a);

		int _a = 0;
		if (a != null) {
			if (a.size() == 1) {
				_a = ((CenterNews) a.get(0)).getId();
			}
		}
		msg.put("index1", this.service.findByHql(1, 3,
				" from CenterNews  t where  t.typekey ='weeego01' and  t.id <> "
						+ _a + "  order by t.id desc"));

		msg
				.put(
						"index2",
						this.service
								.findByHql(
										1,
										3,
										" from CenterNews  t where  t.typekey ='weeego02' and  t.pic<> ''   order by t.id desc"));

		msg
				.put(
						"index3",
						this.service
								.findByHql(
										1,
										5,
										" from CenterNews  t where  t.typekey ='weeego03' and  t.pic<> ''   order by t.id desc"));

		msg
				.put(
						"index4",
						this.service
								.findByHql(1, 10,
										" from CenterNews  t where  t.typekey ='weeego04'   order by t.id desc"));

		msg
				.put(
						"index5",
						this.service
								.findByHql(1, 5,
										" from CenterNews  t where  t.typekey ='weeego05'   order by t.id desc"));

		// this.saveString("index.html", ServletActionContext.getRequest()
		// .getRealPath("/"), this
		// .getOneHtml("http://localhost:8080/weeego/weeego_index"));

		return "index";
	}

	public String about() throws Exception {

		List a = new ArrayList();
		msg
				.put(
						"service",
						this.service
								.findByHql(1, 10,
										" from CenterNews  t where  t.typekey ='weeego04'   order by t.id desc"));
		msg
				.put(
						"work",
						this.service
								.findByHql(1, 10,
										" from CenterNews  t where  t.typekey ='weeego03'   order by t.id desc"));
		return "index";
	}

	public String works() throws Exception {

		msg
				.put(
						"index",
						this.service
								.findByHql(getNowpage(), 9,
										" from CenterNews  t where  t.typekey ='weeego03'   order by t.id desc"));

		msg
				.put(
						"service",
						this.service
								.findByHql(1, 18,
										" from CenterNews  t where  t.typekey ='weeego04'   order by t.id desc"));

		return "index";
	}

	public String servce() throws Exception {

		logger.info(getNowpage() + "................");

		msg
				.put(
						"index",
						this.service
								.findByHql(getNowpage(), 5,
										" from CenterNews  t where  t.typekey ='weeego04'   order by t.id desc"));

		msg
				.put(
						"sidebar",
						this.service
								.findByHql(1, 18,
										" from CenterNews  t where  t.typekey ='weeego02'   order by t.id desc"));

		return "index";
	}

	public String news() throws Exception {

		if (this.id > 0) {
			this.objectForm = this.service.findObjectById(new CenterNews(),
					this.id);
		}
		msg
				.put(
						"index",
						this.service
								.findByHql(getNowpage(), 5,
										" from CenterNews  t where  t.typekey ='weeego04'   order by t.id desc"));

		msg
				.put(
						"work",
						this.service
								.findByHql(1, 10,
										" from CenterNews  t where  t.typekey ='weeego03'   order by t.id desc"));

		return "index";
	}

	public String message() throws Exception {

		List a = new ArrayList();

		return "index";
	}

	public BaseService getService() {
		return service;
	}

	public void setService(BaseService service) {
		this.service = service;
	}

	public Map getMsg() {
		return msg;
	}

	public void setMsg(Map msg) {
		this.msg = msg;
	}

}
